package com.shujia

object Demo16String {
  def main(args: Array[String]): Unit = {
    //定义一个字符串
    val str = "java"

    //定义多行的字符串
    val sql: String =
      """
        |select clazz,count(1)
        |from student
        |group by clazz
        |
        |""".stripMargin

    println(sql)

    //2、字符串拼接
    val name = "张三"
    val age = 23
    val clazz = "文科一班"

    //使用加号拼接字符串
    val str2: String = "name:" + name + ",age:" + age + ",clazz:" + clazz
    println(str2)

    //在Java中可以使用StringBuffer提升性能
    val buffer = new StringBuffer()
    buffer.append("name:")
      .append(name)
      .append(",age:")
      .append(age)
      .append(",clazz:")
      .append(clazz)

    println(buffer)

    //在scala中实现字符串拼接
    //底层时StringBuilder
    val into: String = s"name:${name}age:$age,clazz:$clazz"
    println(into)

    val sex = "女"
    val sql1: String =
      s"""
         |select clazz,count(1)
         |from student
         |where
         |sex = '$sex'
         |group by clazz
         |
         |""".stripMargin

    println(sql1)
  }
}
